package org.bees.cms.web.util.velocity.renderer;

import java.io.Serializable;

import net.sf.json.JSONObject;

import org.bees.cms.web.util.Beans;

public abstract class AbstractRenderer implements Renderer {
	protected String id = "";
	protected String clazz = "";
	protected String style = "";
	protected String property;

	@Override
	public void initialize(JSONObject json) throws Exception {
		id = json == null ? id : json.containsKey("id") ? json.getString("id") : id;
		clazz = json == null ? clazz : json.containsKey("clazz") ? json.getString("clazz") : clazz;
		style = json == null ? style : json.containsKey("style") ? json.getString("style") : style;
		property = json == null ? property : json.containsKey("property") ? json.getString("property") : property;
	}

	@Override
	public String render(Serializable t) throws Exception {
		return "<span id='" + id + "' class='" + clazz + "' style='" + style + "'>" + Beans.getString(t, property) + "</span>";
	}

	@Override
	public void destroy() throws Exception {
		id = null;
		clazz = null;
		style = null;
		property = null;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getClazz() {
		return clazz;
	}

	public void setClazz(String clazz) {
		this.clazz = clazz;
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public String getProperty() {
		return property;
	}

	public void setProperty(String property) {
		this.property = property;
	}

}
